using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GolemController : MonoBehaviour
{
    public DialogueData_SO dialogueDataSo;
    public AudioClip firstBattle;
    public bool canTalk;
    private bool haveTalked = true;
    
    private void OnTriggerEnter(Collider other)
    {
        Debug.Log("canTalk");
        if (other.CompareTag("Player"))
        {
            canTalk = true;
            GameManager.Instance.freeLookCamera.m_Orbits[0].m_Height = 25;
            GameManager.Instance.freeLookCamera.m_Orbits[0].m_Radius = 20;
            GameManager.Instance.freeLookCamera.m_YAxis.Value = 1;
            GameManager.Instance.freeLookCamera.m_LookAt = transform;
            AudioManager.Instance.AudioSource.Pause();
            AudioManager.Instance.AudioSource.clip = firstBattle;
            AudioManager.Instance.AudioSource.Play();
        }
    }

    private void OnTriggerExit(Collider other)
    {
        if (other.CompareTag("Player"))
        {
            DialogueManager.Instance.dialoguePanel.gameObject.SetActive(false);
            canTalk = false;
        }
    }

    
    private void Update()
    {
        if (canTalk&&haveTalked)
        {
            OpenDialogue();
            canTalk = false;
            haveTalked = false;
        }
    }

    private void OpenDialogue()
    {
        //打开UI面板
        //传输对话的内容
        DialogueManager.Instance.updateDialogueData(dialogueDataSo);
        DialogueManager.Instance.updateDialougueUI(dialogueDataSo.DialogPieces[0]);
    }
}
